<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/31
 * Time: 15:43
 */

namespace app\admin\controller;

use data\model\User;
use think\Controller;
use think\Loader;
Loader::addNamespace('data','data/');

class Login extends Controller
{
    public function login(){
        if(request()->post()){
            $username = input('username');
            $password = md5(input('password'));
            $rs =User::get(['username'=>$username]);
            if($password == $rs['password']){
                session('name',$rs['username']);
                session('uid',$rs['userid']);
                session('avatar',$rs['avatar']);
                $this->success('登录成功','index/index');
            }else{
                $this->error('登录失败请重新登录');
            }
        }
        return $this->fetch('admin/login/login');
    }
    public function logout(){
        session(null);
         $this->success('退出登录','login');
    }
}